package com.xjl;


import com.xjl.dao.UserDao;
import com.xjl.pojo.User;
import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {
    public static void main(String[] args) throws IOException {
        //定义mybatis配置文件的路径
        String resource = "mybatis-config.xml";
        InputStream inputStream = Resources.getResourceAsStream(resource);
        SqlSessionFactory sqlSessionFactory = new SqlSessionFactoryBuilder().build(inputStream);
        //获取Sqlsession对象
        SqlSession sqlSession = sqlSessionFactory.openSession();
        //获取UserDao实现类对象
        UserDao userDao = sqlSession.getMapper(UserDao.class);
        //调用方法测试
//        List<User> userList = userDao.findAll();
//        User user = userDao.findById(3);
//        System.out.println(user);
//        System.out.println(userList);
//        User user=userDao.findByUser(new User("1","UZI","19","上海"));
//        System.out.println(user);
//
//        Map map=new HashMap<>();
//        map.put("id","1");
//        map.put("username","UZI");
//        map.put("address","上海");
//        map.put("age","19");
//
//        User user2=userDao.findByMap(map);
//        System.out.println(user2);
//
//        User user3=userDao.findByCondition(1,"UZI");
//        System.out.println(user3);

//        User user=new User(null,"若风","35","上海");
//        userDao.insertUser(user);

//        userDao.deteleById(4);

//        userDao.updateUser(new User("1","UZI","100","sahnghai"));
//        sqlSession.commit();
//        System.out.println(userDao.findById(1));

//        List<User> users=userDao.findByCondition(null,null);
//        System.out.println(users);

        //userDao.updateUser(new User("2","PDD",null,null));
//        Integer[] ids={3,4,5,3,3,};
//        userDao.findByIds(ids);
//        userDao.selectChose(new User(null,null,"20",null));
        List<User> users=userDao.findAll();
        //释放资源
        sqlSession.close();

    }
}